<template>
  <div>
    <el-button type="primary" @click="printContent">点击打印</el-button>
    <!-- 打印内容 -->
    <el-card>
      <div ref="printContent">
        我是打印数据测试
      </div>
    </el-card>
    {{"我是测试" + str}}
  </div>
</template>
<script>
export default {
  name:"Test",
  data(){
    return{
      str:""
    }
  },
  methods: {
    printContent() {

      let printContents = this.$refs.printContent.innerHTML; // 获取要打印的内容

      console.log(printContents)

      let originalContents = document.body.innerHTML;// 保存原始内容

      document.body.innerHTML = printContents; // 替换为要打印的内容

      window.print(); // 打印

      document.body.innerHTML = originalContents;// 恢复原始内容
    }
  },created() {
    this.str = this.$route.params.id
  }
};
</script>